function [savings_EWM] = generate_tables_baseline(sample_cross,winter_prevuse,wave,cost,bsimax,SMC,savedir,fbase,rule,fullsample)

% This function calls two functions to produce results for the savings table: 
% 1) quadrant rule grid search algorithms; 
% 2) cubic rule cplex linear programming solver 
% The savings are for treatment rules in the two-dimensional space
% based on the selected covariate and baseline usage. Covariate choices are
% min, max, and standard deviation. 

% Inputs: 
% (1) sample: cross-sectional dataset with electricity consumption, 
% covariates, and propensity scores
% (2) winter_prevuse: indicates whether baseline consumption is calculated 
% as the mean of consumption in winter months (Jan and Feb) or as the mean
% of specified pre-treatment periods
% (3) wave: indicates whether the output is wave-specific (=3,6,or 7) or
% for the pooled sample (=0)
% (4) cost: =1 use cost at outcome;  =0 use kWh as outcome
% (5) bsimax: number of bootstrap runs
% (6) SMC: =1 use social marginal cost; =0 use retail electricity price
% (7) savedir: directory to save the savings table 
% (8) fbase: string used to indicate the propensity score and baseline
% months specification for output table 
% (9) rule: quadrant or cubic rule
% (10) fullsample: =1 if full sample, =0 if estimation sample

% Output: 
% (1) savings_EWM: table summarizing savings from quadrant or cubic rules 

%% Specify covariates of interest
covariates={'min' 'max' 'std'};

%% Specify the private marginal cost used to calculate cost savings cost 
if (cost)
    tcost = 0.765; % cost of sending out letter for each household. see footnote in paper for detailed calculation.
else
    tcost = 0;
end

%%
if rule=="quadrant"
%% Calculate EWM quadrant savings
    savings_EWM_univariate       = generate_results_onedimension(bsimax,sample_cross,wave,tcost,'income',winter_prevuse,SMC,fullsample,savedir,fbase);
    savings_EWM_quadrant_min     = generate_results_quadrant_rule(bsimax,sample_cross,wave,tcost,covariates{1},winter_prevuse,SMC,fullsample,savedir,fbase);
    savings_EWM_quadrant_max     = generate_results_quadrant_rule(bsimax,sample_cross,wave,tcost,covariates{2},winter_prevuse,SMC,fullsample,savedir,fbase);
    savings_EWM_quadrant_std     = generate_results_quadrant_rule(bsimax,sample_cross,wave,tcost,covariates{3},winter_prevuse,SMC,fullsample,savedir,fbase);
    savings_EWM = [savings_EWM_univariate; savings_EWM_quadrant_min; savings_EWM_quadrant_max; savings_EWM_quadrant_std];
elseif rule=="cubic"
%% Calculate EWM cubic savings 
    savings_EWM_cubic_min     = generate_results_cubic_rule(bsimax,sample_cross,wave,tcost,covariates{1},winter_prevuse,SMC,fullsample,savedir,fbase);
    savings_EWM_cubic_max     = generate_results_cubic_rule(bsimax,sample_cross,wave,tcost,covariates{2},winter_prevuse,SMC,fullsample,savedir,fbase);
    savings_EWM_cubic_std     = generate_results_cubic_rule(bsimax,sample_cross,wave,tcost,covariates{3},winter_prevuse,SMC,fullsample,savedir,fbase);
    savings_EWM = [savings_EWM_cubic_min; savings_EWM_cubic_max; savings_EWM_cubic_std];
end

end